<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1">
    <title th:if="${a eq 1}">添加用户</title>
    <title th:each="reviseUser:${reviseUser}">修改用户</title>
    <link rel="shortcut icon" th:href="@{/pages/logo-1.ico}" href="../static/pages/logo-1.ico"/>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" href="../static/layui/css/layui.css">
    <link rel="stylesheet" th:href="@{/layui/css/admin.css}" href="../static/layui/css/admin.css">
    <link rel="stylesheet" th:href="@{/layui/css/log.css}" href="../static/layui/css/log.css">
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div th:each="reviseUser:${reviseUser}" class="layadmin-user-login-main">
        <div class=" layadmin-user-login-header">
            <h2>修改用户</h2>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input th:value="${reviseUser.id}" type="text" readonly name="id" id="id" lay-verify="required" placeholder="用户ID" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="id" id="name" th:value="${reviseUser.name}" lay-verify="required" placeholder="用户名" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="name" id="age" th:value="${reviseUser.age}" lay-verify="required" placeholder="年龄" class="layui-input">
            </div>
<!--            <div class="layui-form-item">-->
<!--                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>-->
<!--                <input type="text" name="unit" id="gender" lay-verify="required" placeholder="性别" class="layui-input">-->
<!--            </div>-->
            <div class="layui-form-item">
                <select name="modules" id="gender"  lay-verify="required" lay-search="">
                    <option th:value="${reviseUser.gender}" value="">性别</option>
                    <option value="男">男</option>
                    <option value="女">女</option>
                </select>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="space" id="phone" th:value="${reviseUser.phone}" lay-verify="required" placeholder="电话" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="password" name="supplierId" id="password" lay-verify="required" placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="password" name="supplierId" id="passwordAgain" lay-verify="required" placeholder="确认密码" class="layui-input">
            </div>
            <!--            <div class="layui-inline">-->
            <!--&lt;!&ndash;                <label class="layui-form-label">搜索选择框</label>&ndash;&gt;-->
            <!--                <div class="layui-input-inline">-->
            <!--                    <select name="modules" lay-verify="required" lay-search="">-->
            <!--                        <option value="">供应商编号</option>-->
            <!--                        <option value="1">layer</option>-->
            <!--                        <option value="2">form</option>-->
            <!--                    </select>-->
            <!--                </div>-->
            <!--            </div>-->
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit" onclick="submit();" id="addpurlog">确认</button>
            </div>
            <div class="layui-form-item">
                <a href="javascript:history.go(-1);" lay-filter="LAY-user-login-submit" class="layui-btn layui-btn-fluid"  id="out">取消</a>
            </div>
        </div>
    </div>

    <div th:if="${a eq 1}" class="layadmin-user-login-main">
        <div class=" layadmin-user-login-header">
            <h2>添加用户</h2>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="id" id="name" lay-verify="required" placeholder="用户名" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="name" id="age" lay-verify="required" placeholder="年龄" class="layui-input">
            </div>
            <!--            <div class="layui-form-item">-->
            <!--                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>-->
            <!--                <input type="text" name="unit" id="gender" lay-verify="required" placeholder="性别" class="layui-input">-->
            <!--            </div>-->
            <div class="layui-form-item">
                <select name="modules" id="gender" lay-verify="required" lay-search="">
                    <option value="">性别</option>
                    <option value="男">男</option>
                    <option value="女">女</option>
                </select>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="space" id="phone" lay-verify="required" placeholder="电话" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="password" name="supplierId" id="password" lay-verify="required" placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="password" name="supplierId" id="passwordAgain" lay-verify="required" placeholder="确认密码" class="layui-input">
            </div>
            <!--            <div class="layui-inline">-->
            <!--&lt;!&ndash;                <label class="layui-form-label">搜索选择框</label>&ndash;&gt;-->
            <!--                <div class="layui-input-inline">-->
            <!--                    <select name="modules" lay-verify="required" lay-search="">-->
            <!--                        <option value="">供应商编号</option>-->
            <!--                        <option value="1">layer</option>-->
            <!--                        <option value="2">form</option>-->
            <!--                    </select>-->
            <!--                </div>-->
            <!--            </div>-->
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit" onclick="submit();" id="addpurlog">确认</button>
            </div>
            <div class="layui-form-item">
                <a href="javascript:history.go(-1);" lay-filter="LAY-user-login-submit" class="layui-btn layui-btn-fluid"  id="out">取消</a>
            </div>
        </div>
    </div>

</div>

<script src="../static/layui/layui.js" th:src="@{/layui/layui.js}" type="text/javascript"></script>
<script src="../static/js/vue.min.js" th:src="@{/js/vue.min.js}" type="text/javascript"></script>
<script src="../static/js/jquery-3.6.3.min.js" th:src="@{/js/jquery-3.6.3.min.js}" type="text/javascript"></script>
<script th:inline="javascript">

    //验证输入的密码是否相同；
    $("#passwordAgain").blur(function() {
        var password = $("#password").val();
        var passwordAgain = $("#passwordAgain").val();
        if (password != passwordAgain) {
            layer.msg("两次输入的密码不一致", {
                "icon": 2,
                "time": 2000
            });
            $("#passwordAgain").val("");
            return false;
        }
        return true;
    });
    function submit(){
        let id = $('#id').val()
        let name = $('#name').val()
        let age = $('#age').val()
        let gender = $('#gender').val()
        let phone = $('#phone').val()
        let password = $('#password').val()
        let passwordAgain = $('#passwordAgain').val()
        if (password == passwordAgain) {
            $.ajax({
                url: "/login/addyhzc",
                data: {
                    id:id,
                    name: name,
                    age: age,
                    gender: gender,
                    phone: phone,
                    password: password
                },
                type: "post",
                dataType: "json",
                // cache : false,
                // async : false,//设置同步（ajax请求此处需求为跳转而不是局部页面刷新）
                success: function (addyh) {
                    if (addyh == 100) {
                        window.location.href = "/xt/xtyhgl";
                    }else if (addyh == -100) {
                        window.location.href = "/xt/xtyhgl";
                    }else if (addyh == 200) {
                        layer.open({
                            title: ''
                            , content: '系统错误,请联系管理员!'
                        });
                    } else {
                        // window.location.href = "/";
                        layer.open({
                            title: ''
                            , content: '用户名不可与用户名、管理员名重复，请重新输入!'
                        });
                    }
                }
            })
        }
    }
</script>
</body>
</html>
